package com.dingqb.ktdemo.oop

/**
 *  初始化主构造器-> 属性-> init-> 次构造器
 */
class ClassObj2 constructor(name: String) {

    var age: Int = 0;
    var newName = name;

    constructor(name: String, age: Int) : this(name) {
        println("sub constructor ")
    }

    init {
        println("init--$name")
    }

    fun printName() {
        println("getName()--$newName");
    }

}

/**
 * 初始化主构造器-> 属性-> init-> 次构造器
 */
class ClassSub {
    constructor(name: String) {
        println("main constructor:" + name)
    }

    constructor(name: String, age: Int) : this(name) {
        println("sub constructor:" + age)
    }

    var newName: String = "init newName"

    init {
        println("init:$newName");
    }
}

fun main() {
    var obj2 = ClassObj2("Tom1", 21);
    obj2.printName();
    var sub = ClassSub("Tom2", 22);

}